package edu.sysu.cshare.control;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import edu.sysu.cshare.util.HibernateSessionFactory;

public class SystemManager {

	// TODO FTP权限 安全
	public static class RemoteConfig {

		public static String getFTPHost() {
			return HibernateSessionFactory.getConfiguration().getProperty(
					"edu.sysu.cshare.ftp.host");
		}

		public static String getFTPUser() {
			return HibernateSessionFactory.getConfiguration().getProperty(
			"edu.sysu.cshare.ftp.user");
		}

		public static String getFTPPassword() {
			return HibernateSessionFactory.getConfiguration().getProperty(
			"edu.sysu.cshare.ftp.password");
		}

		public static String getFTPRootDir() {
			return null;
		}

		public static String getMsgAttDir() {
			return HibernateSessionFactory.getConfiguration().getProperty(
			"edu.sysu.cshare.ftp.msgattdir");
		}

	}

	public static class LocalConfig {
		private static Properties props = new Properties();
		private static InputStream inputFile;
		private static FileOutputStream outputFile;
		private static String propPath = "config.properties";

		public static String getLastDirPath() {
			String value = "";
			try {
				inputFile = new BufferedInputStream(new FileInputStream(
						propPath));
				props.load(inputFile);
				inputFile.close();
				value = props.getProperty("LastDirPath");
			} catch (Exception e) {
				e.printStackTrace();
			}
			return value;

		}

		public static void setLastDirPath(String path) {
			try {
				File file = new File(propPath);
				if (!file.exists())
					file.createNewFile();
				outputFile = new FileOutputStream(propPath);
				props.setProperty("LastDirPath", path);
				props.store(outputFile, null);
			} catch (IOException e) {
				e.printStackTrace();
			} finally {
				try {
					outputFile.close();
				} catch (IOException e) {
				}
			}
		}

	}
}
